/**
* @file 附件列表
* @author  zhoushu
* @date  17/1/12
*/
<template>
  <div class="file-list" v-if="file || btn">
    <p v-if="file.length>0">{{title||''}}附件（{{file.length}}）</p>
    <ul class="file">
      <li
        :class="{
        'word':getFileType(list.extension) == '0',
        'excel':getFileType(list.extension) == '1',
        'ppt':getFileType(list.extension) == '2',
        'pdf':getFileType(list.extension) == '3',
        'other':getFileType(list.extension) == '4'}"
        v-for="list in file" @tap="clickFile(list.fileUrl)">
        <div class="name">
          <label class="iconFamily"
                 :class="{
                 'fileTypeWork':getFileType(list.extension) == '0',
                 'fileTypeExl':getFileType(list.extension) == '1',
                 'fileTypePpt':getFileType(list.extension) == '2',
                 'fileTypePdf':getFileType(list.extension) == '3',
                 'fileTypeOther':getFileType(list.extension) == '4'}"></label>
          <p class="mui-ellipsis" v-text="list.originName"></p>
        </div>
        <p class="des">
          <span>{{list.extension}}</span>|<span>{{list.createdOn}}</span>|<span>{{list.fileSize}}</span>
        </p>
      </li>
      <div class="btn" v-if="btn">
        <div v-for="list in btn" class="detailButton" @tap="clickBtn(list)">
          <span>{{list.name}}</span>
        </div>
      </div>
    </ul>
  </div>
</template>
<style lang="less" rel="stylesheet/less">
  @import 'crmFile.css';
</style>
<script>
  var nativeApi = require('nativeApi');
  export default{
    props: {
      file: [],  //  附件数据
      title: '',
      btn: [] //  需要显示的文件夹数据
    },
    methods: {
      clickFile: function (pathUrl) {
        /*打开附件*/
        var suffix = pathUrl.substring(pathUrl.lastIndexOf(".") + 1, pathUrl.length).toLocaleLowerCase(),
          suffixType = "";
        if (mui.os.ios || mui.os.android) {
          if (".jpg|.jpeg|.gif|.bmp|.png|".indexOf(suffix + "|") > -1) {
            /*图片*/
            suffixType = "IMAGE";
          } else if (".mp4|.mov|".indexOf(suffix + "|") > -1) {
            /*视频*/
            suffixType = "VEDIO";
          } else if (".amr|.wav|".indexOf(suffix + "|") > -1) {
            /*音频*/
            suffixType = "AUDIO";
          } else if (".txt|".indexOf(suffix + "|") > -1) {
            /*文本*/
            suffixType = "TEXT";
          } else if (".doc|.xls|.ppt|.pptx|.pdf|.docx|.xlsx|".indexOf(suffix + "|") > -1) {
            /*办公*/
            suffixType = "OFFICE";
          } else if (".html|.jsp|.php|.asp|".indexOf(suffix + "|") > -1) {
            /*网页*/
            suffixType = "WEBSITE";
          } else {
            if (window.loginInfo.isEn == true) {
              mui.alert("You can't upload accessory at mobile terminal!", "Tip");
            } else {
              mui.alert("对不起，app不支持该附件类型！", "提示");
            }
            return;
          }
        }
        nativeApi.goDownload({
          "apiJson": {
            "endBack": "2",
            "file": {
              "name": pathUrl.substring(pathUrl.lastIndexOf("/") + 1, pathUrl.length),
              "sha": pathUrl.substring(pathUrl.lastIndexOf("/") + 1, pathUrl.lastIndexOf(".")),
              "size": "",
              "status": "1",
              "type": pathUrl.substring(pathUrl.lastIndexOf(".") + 1, pathUrl.length),
              "url": pathUrl
            },
            "type": suffixType
          },
          callback: function (result) {
          }
        });
      },
      clickBtn: function (item) {
        this.$dispatch('clickBtn', item);
      },
      getFileType: function (extension) {
        var type = '4'; //  其他
        extension = extension.toLocaleLowerCase();
        if (".doc|.docx|".indexOf(extension) != -1) {
          type = '0'; //  word
        } else if (".xls|.xlsx|".indexOf(extension) != -1) {
          type = '1'; //  excel
        } else if (".ppt|.pptx|".indexOf(extension) != -1) {
          type = '2'; //  ppt
        } else if (".pdf|".indexOf(extension) != -1) {
          type = '3'; //  pdf
        }
        return type;
      }
    },
    created: function () {
    },
    route: {
      data: function () {
      }
    },
    ready: function () {
    }
  };
</script>
